package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 用户登录请求参数类
 *
 * @author lijian
 * @version 2014年3月31日 - 下午7:48:20
 */
public class UserLoginRequest extends Request {

	/**
	 * 账号/邮箱/手机号码
	 */
	private String username;
	
	/**
	 * 密码
	 */
	private String password;

	/**
	 * 登陆ip
	 */
	private String ip;
	
	/** */
	public UserLoginRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {

		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.username = requestInfo.getParameter(ApiUrlParamEnum.username.getParamName(), "");
		this.password = requestInfo.getParameter(ApiUrlParamEnum.password.getParamName(), "");
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		if ("127.0.0.1".equals(ip)) {
			this.ip = requestInfo.getUserIp();
		}
		if (StringUtil.isEmpty(username)) {
			throw new RequestIllegalException("账号名/邮箱/手机号码不能为空");
		}
		
		if (StringUtil.isEmpty(password)) {
			throw new RequestIllegalException("密码不能为空");
		}

		if (StringUtil.isEmpty(ip)) {
			throw new RequestIllegalException("ip不能为空");
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	
}
